package com.bjsxt.controller;

import com.bjsxt.Service.TbContentCategoryService;
import com.bjsxt.commons.exception.DaoException;
import com.bjsxt.commons.pojo.BaizhanResult;
import com.bjsxt.pojo.TbContentCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author coder_z
 * @date 2023/2/18
 **/
@RestController
@RequestMapping("/backend/contentCategory")
public class TbContentCategoryController {
    @Autowired
    private TbContentCategoryService tbContentCategoryService;

    /**
     * 查询分类信息
     * @param id
     * @return
     */
    @PostMapping("/selectContentCategoryByParentId")
    public BaizhanResult showCategory(@RequestParam(defaultValue = "0") long id){
    return tbContentCategoryService.selectByPid(id);
    }

    /**
     * 新增内容分类
     * @param tbContentCategory
     * @return
     */
    @PostMapping("/insertContentCategory")
    public BaizhanResult insert(TbContentCategory tbContentCategory){
        try {
            return tbContentCategoryService.insert(tbContentCategory);
        } catch (DaoException e) {
            e.printStackTrace();
            return BaizhanResult.error(e.getMessage());
        }
    }
    @PostMapping("/deleteContentCategoryById")
    public BaizhanResult deleteStatusById(long id){
        try {
            return tbContentCategoryService.deleteStatusById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return BaizhanResult.error(e.getMessage());
        }
    }
    @PostMapping("/updateContentCategory")
    public BaizhanResult updateById(TbContentCategory category){
        try {
            return tbContentCategoryService.updateNameById(category);
        } catch (Exception e) {
            e.printStackTrace();
            return BaizhanResult.error(e.getMessage());
        }
    }



}
